<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.11.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>cppMISC: include/details/linuxTimer.hpp 源文件</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../cookie.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript" src="../../darkmode_toggle.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">cppMISC<span id="projectnumber">&#160;v1.1</span>
   </div>
   <div id="projectbrief">cppMisc 文档系统</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.11.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(1); });
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('../../',true,false,'search.php','搜索',false);
  $(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">载入中...</div>
<div class="SRStatus" id="Searching">搜索中...</div>
<div class="SRStatus" id="NoMatches">未找到</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="../../dir_ae5bdaf1b45f3c0e6fd5dd3984d2eafd.html">details</a></li>  </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
  <div class="headertitle"><div class="title">linuxTimer.hpp</div></div>
</div><!--header-->
<div class="contents">
<a href="../../d2/de0/linux_timer_8hpp.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span> </div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno">    8</span><span class="preprocessor">#pragma once</span></div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno">    9</span> </div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno">   10</span><span class="preprocessor">#include &lt;signal.h&gt;</span></div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span><span class="preprocessor">#include &lt;time.h&gt;</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span> </div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno">   13</span><span class="preprocessor">#include &lt;atomic&gt;</span></div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno">   14</span><span class="preprocessor">#include &lt;mutex&gt;</span></div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno">   15</span><span class="preprocessor">#include &lt;functional&gt;</span></div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno">   16</span> </div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno">   17</span><span class="preprocessor">#include &quot;<a class="code" href="../../db/d24/itimer_8hpp.html">itimer.hpp</a>&quot;</span></div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno">   18</span> </div>
<div class="foldopen" id="foldopen00019" data-start="{" data-end="};">
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno"><a class="line" href="../../d9/d91/classlinux_timer.html">   19</a></span><span class="keyword">class </span><a class="code hl_class" href="../../d9/d91/classlinux_timer.html">linuxTimer</a>: <span class="keyword">public</span> <a class="code hl_struct" href="../../d2/d38/structi_timer.html">iTimer</a></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno">   20</span>{</div>
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno">   21</span>    <span class="keyword">friend</span> <span class="keywordtype">void</span> <a class="code hl_friend" href="../../d9/d91/classlinux_timer.html#a6b4fa40672b13152c51b3073b180ba6e">linux_on_timer</a>( sigval info );</div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno">   22</span><span class="keyword">public</span>:</div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno">   23</span>    </div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno">   24</span><span class="keyword">private</span>:</div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno">   25</span>    std::atomic&lt;bool&gt;           __m_is_one_shot;               <span class="comment">// 计时器是否是单次计时器</span></div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno">   26</span>    std::atomic&lt;long&gt;           __m_tick;                      <span class="comment">// 最大计时量</span></div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno">   27</span>    std::atomic&lt;bool&gt;           __m_is_run;                    <span class="comment">// 计时线程是否正在运行</span></div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno">   28</span>    std::atomic&lt;bool&gt;           __m_reset;                     <span class="comment">// 复位计时器</span></div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno">   29</span> </div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno">   30</span>    <span class="keyword">struct </span>sigevent             __m_evt;                       <span class="comment">// 事件通讯</span></div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno">   31</span>    std::atomic&lt;timer_t&gt;        __m_id;                        <span class="comment">// timerID</span></div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno">   32</span>    <span class="keyword">struct </span>itimerspec           __m_new;                       <span class="comment">// 计时参数</span></div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno">   33</span>    std::mutex                  __m_mutex;</div>
<div class="line"><a id="l00034" name="l00034"></a><span class="lineno">   34</span> </div>
<div class="line"><a id="l00035" name="l00035"></a><span class="lineno">   35</span>    std::function&lt;void()&gt;     __m_cb;                        <span class="comment">//要调用的事件发生的时候调用这个函数对象</span></div>
<div class="line"><a id="l00036" name="l00036"></a><span class="lineno">   36</span><span class="keyword">private</span>:</div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span>    <a class="code hl_enumeration" href="../../d2/d38/structi_timer.html#a31bdd3250ca6c5542d0ec156bd82c5ab">emErrCode</a> __init_timer();</div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span>    <span class="keywordtype">void</span> __on_sys_timer();</div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno">   42</span><span class="keyword">public</span>:</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span>    <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#abeebd83796551a74702a0660900f7e5e">linuxTimer</a>();</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno">   44</span>    <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#abeebd83796551a74702a0660900f7e5e">linuxTimer</a>( <span class="keywordtype">long</span> ms , <span class="keywordtype">bool</span> oneShot = <span class="keyword">false</span> );</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span>    <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#abeebd83796551a74702a0660900f7e5e">linuxTimer</a>( std::function&lt;<span class="keywordtype">void</span>()&gt; fun , <span class="keywordtype">long</span> ms , <span class="keywordtype">bool</span> onShot = <span class="keyword">false</span> );</div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno"><a class="line" href="../../d9/d91/classlinux_timer.html#a92d01213e0512dc61a339d734c56a3e5">   46</a></span>    <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#a92d01213e0512dc61a339d734c56a3e5">~linuxTimer</a>(){ <span class="keywordflow">if</span>( __m_is_run == <span class="keyword">true</span> ) <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#a9f8127cc511dc74220398e4ed6758551">Stop</a>(); }</div>
<div class="foldopen" id="foldopen00050" data-start="{" data-end="}">
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno"><a class="line" href="../../d9/d91/classlinux_timer.html#abf7528c1f1ef1fd905cea11a3392e06e">   50</a></span>    <span class="keyword">inline</span> <span class="keywordtype">long</span> <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#abf7528c1f1ef1fd905cea11a3392e06e">operator()</a>()<span class="keyword">const</span></div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno">   51</span><span class="keyword">    </span>{</div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno">   52</span>        <span class="keywordflow">return</span> __m_tick;</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno">   53</span>    }</div>
</div>
<div class="foldopen" id="foldopen00054" data-start="{" data-end="}">
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"><a class="line" href="../../d9/d91/classlinux_timer.html#ac7e07e53a738b37156355a46fba45715">   54</a></span>    <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#ac7e07e53a738b37156355a46fba45715">operator()</a>( <span class="keywordtype">long</span> t )</div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno">   55</span>    { </div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno">   56</span>        __m_tick = t; </div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno">   57</span>    }</div>
</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno">   63</span>    <span class="keyword">virtual</span> <a class="code hl_enumeration" href="../../d2/d38/structi_timer.html#a31bdd3250ca6c5542d0ec156bd82c5ab">emErrCode</a> <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#a93a10e9e8a6ee3079f2c98425ce433aa">Start</a>( <span class="keywordtype">long</span> ms = -1, <span class="keywordtype">bool</span> oneShot = <span class="keyword">false</span> ) final;</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno">   68</span>    virtual <span class="keywordtype">void</span> <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#a7663f68ea95168f3d72c8e0199c32bed">SetOwner</a>( <a class="code hl_namespace" href="../../d8/dcc/namespacestd.html">std</a>::function&lt;<span class="keywordtype">void</span>(  )&gt; fun ) final;</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno">   72</span>    virtual <a class="code hl_enumeration" href="../../d2/d38/structi_timer.html#a31bdd3250ca6c5542d0ec156bd82c5ab">emErrCode</a> <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#a9f8127cc511dc74220398e4ed6758551">Stop</a>(  ) final;</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span>    virtual <span class="keywordtype">bool</span> <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#a64e54112f6cb165dee88a5d0ae8045c0">IsRuning</a>(  ) final;</div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"><a class="line" href="../../d9/d91/classlinux_timer.html#a399b8f2aecafb381a836e7f89a3cb865">   77</a></span>    virtual <span class="keywordtype">void</span> <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#a399b8f2aecafb381a836e7f89a3cb865">setTick</a>(<span class="keywordtype">long</span> t) final{ __m_tick = t ;}</div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span>    <span class="keyword">virtual</span> <a class="code hl_enumeration" href="../../d2/d38/structi_timer.html#a31bdd3250ca6c5542d0ec156bd82c5ab">emErrCode</a> <a class="code hl_function" href="../../d9/d91/classlinux_timer.html#a5472bac2316d32981b30f6a8b1600e83">Reset</a>() final;</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno">   82</span>};</div>
</div>
<div class="ttc" id="aclasslinux_timer_html"><div class="ttname"><a href="../../d9/d91/classlinux_timer.html">linuxTimer</a></div><div class="ttdoc">遵循POSIX标准的TIMER</div><div class="ttdef"><b>定义</b> <a href="#l00019">linuxTimer.hpp:20</a></div></div>
<div class="ttc" id="aclasslinux_timer_html_a399b8f2aecafb381a836e7f89a3cb865"><div class="ttname"><a href="../../d9/d91/classlinux_timer.html#a399b8f2aecafb381a836e7f89a3cb865">linuxTimer::setTick</a></div><div class="ttdeci">virtual void setTick(long t) final</div><div class="ttdef"><b>定义</b> <a href="#l00077">linuxTimer.hpp:77</a></div></div>
<div class="ttc" id="aclasslinux_timer_html_a5472bac2316d32981b30f6a8b1600e83"><div class="ttname"><a href="../../d9/d91/classlinux_timer.html#a5472bac2316d32981b30f6a8b1600e83">linuxTimer::Reset</a></div><div class="ttdeci">virtual emErrCode Reset() final</div><div class="ttdoc">复位计时，让计时器从零开始计时</div><div class="ttdef"><b>定义</b> <a href="../../d1/d91/linux_timer_8cpp_source.html#l00179">linuxTimer.cpp:179</a></div></div>
<div class="ttc" id="aclasslinux_timer_html_a64e54112f6cb165dee88a5d0ae8045c0"><div class="ttname"><a href="../../d9/d91/classlinux_timer.html#a64e54112f6cb165dee88a5d0ae8045c0">linuxTimer::IsRuning</a></div><div class="ttdeci">virtual bool IsRuning() final</div><div class="ttdoc">判断计时器是否正在运行</div><div class="ttdef"><b>定义</b> <a href="../../d1/d91/linux_timer_8cpp_source.html#l00147">linuxTimer.cpp:147</a></div></div>
<div class="ttc" id="aclasslinux_timer_html_a6b4fa40672b13152c51b3073b180ba6e"><div class="ttname"><a href="../../d9/d91/classlinux_timer.html#a6b4fa40672b13152c51b3073b180ba6e">linuxTimer::linux_on_timer</a></div><div class="ttdeci">friend void linux_on_timer(sigval info)</div><div class="ttdef"><b>定义</b> <a href="../../d1/d91/linux_timer_8cpp_source.html#l00005">linuxTimer.cpp:5</a></div></div>
<div class="ttc" id="aclasslinux_timer_html_a7663f68ea95168f3d72c8e0199c32bed"><div class="ttname"><a href="../../d9/d91/classlinux_timer.html#a7663f68ea95168f3d72c8e0199c32bed">linuxTimer::SetOwner</a></div><div class="ttdeci">virtual void SetOwner(std::function&lt; void()&gt; fun) final</div><div class="ttdoc">指定事件响应函数，</div><div class="ttdef"><b>定义</b> <a href="../../d1/d91/linux_timer_8cpp_source.html#l00122">linuxTimer.cpp:122</a></div></div>
<div class="ttc" id="aclasslinux_timer_html_a92d01213e0512dc61a339d734c56a3e5"><div class="ttname"><a href="../../d9/d91/classlinux_timer.html#a92d01213e0512dc61a339d734c56a3e5">linuxTimer::~linuxTimer</a></div><div class="ttdeci">~linuxTimer()</div><div class="ttdef"><b>定义</b> <a href="#l00046">linuxTimer.hpp:46</a></div></div>
<div class="ttc" id="aclasslinux_timer_html_a93a10e9e8a6ee3079f2c98425ce433aa"><div class="ttname"><a href="../../d9/d91/classlinux_timer.html#a93a10e9e8a6ee3079f2c98425ce433aa">linuxTimer::Start</a></div><div class="ttdeci">virtual emErrCode Start(long ms=-1, bool oneShot=false) final</div><div class="ttdoc">启动或者重启计时器。</div><div class="ttdef"><b>定义</b> <a href="../../d1/d91/linux_timer_8cpp_source.html#l00072">linuxTimer.cpp:72</a></div></div>
<div class="ttc" id="aclasslinux_timer_html_a9f8127cc511dc74220398e4ed6758551"><div class="ttname"><a href="../../d9/d91/classlinux_timer.html#a9f8127cc511dc74220398e4ed6758551">linuxTimer::Stop</a></div><div class="ttdeci">virtual emErrCode Stop() final</div><div class="ttdoc">停止计时器</div><div class="ttdef"><b>定义</b> <a href="../../d1/d91/linux_timer_8cpp_source.html#l00128">linuxTimer.cpp:128</a></div></div>
<div class="ttc" id="aclasslinux_timer_html_abeebd83796551a74702a0660900f7e5e"><div class="ttname"><a href="../../d9/d91/classlinux_timer.html#abeebd83796551a74702a0660900f7e5e">linuxTimer::linuxTimer</a></div><div class="ttdeci">linuxTimer()</div><div class="ttdef"><b>定义</b> <a href="../../d1/d91/linux_timer_8cpp_source.html#l00028">linuxTimer.cpp:28</a></div></div>
<div class="ttc" id="aclasslinux_timer_html_abf7528c1f1ef1fd905cea11a3392e06e"><div class="ttname"><a href="../../d9/d91/classlinux_timer.html#abf7528c1f1ef1fd905cea11a3392e06e">linuxTimer::operator()</a></div><div class="ttdeci">long operator()() const</div><div class="ttdoc">设置和获取计时器计时长度</div><div class="ttdef"><b>定义</b> <a href="#l00050">linuxTimer.hpp:50</a></div></div>
<div class="ttc" id="aclasslinux_timer_html_ac7e07e53a738b37156355a46fba45715"><div class="ttname"><a href="../../d9/d91/classlinux_timer.html#ac7e07e53a738b37156355a46fba45715">linuxTimer::operator()</a></div><div class="ttdeci">void operator()(long t)</div><div class="ttdef"><b>定义</b> <a href="#l00054">linuxTimer.hpp:54</a></div></div>
<div class="ttc" id="aitimer_8hpp_html"><div class="ttname"><a href="../../db/d24/itimer_8hpp.html">itimer.hpp</a></div></div>
<div class="ttc" id="anamespacestd_html"><div class="ttname"><a href="../../d8/dcc/namespacestd.html">std</a></div><div class="ttdef"><b>定义</b> <a href="../../d1/d92/mandarava_2event_8hpp_source.html#l00038">event.hpp:39</a></div></div>
<div class="ttc" id="astructi_timer_html"><div class="ttname"><a href="../../d2/d38/structi_timer.html">iTimer</a></div><div class="ttdoc">定时器定义接口</div><div class="ttdef"><b>定义</b> <a href="../../db/d24/itimer_8hpp_source.html#l00014">itimer.hpp:15</a></div></div>
<div class="ttc" id="astructi_timer_html_a31bdd3250ca6c5542d0ec156bd82c5ab"><div class="ttname"><a href="../../d2/d38/structi_timer.html#a31bdd3250ca6c5542d0ec156bd82c5ab">iTimer::emErrCode</a></div><div class="ttdeci">emErrCode</div><div class="ttdef"><b>定义</b> <a href="../../db/d24/itimer_8hpp_source.html#l00016">itimer.hpp:17</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.11.0
</small></address>
</div><!-- doc-content -->
</body>
</html>
